
/**
 * 判断是否处在HCBrowser环境下
 */
export const isHcBrowser = () => {
  if (!window.getPluginObject) {
    return false
  } else {
    return true
  }
}

/**
 * 获取MAC地址
 */
export const getMacAddress = () => {
  if (!isHcBrowser()) {
    return ''
  }
  let util:string = getPluginObject('HC.Plugin.Utility')
  return util.GetMacAddress()
}

/**
 * 打印单张标签
 * @param {String} tmpl
 * @param {Object} data
 */
export const printRFIDTag = (tmpl: string, data: any) => {
  if (!isHcBrowser()) {
    return
  }
  let printer = getPluginObject('HC.Plugin.Print.LabelPrinter')
  return new Promise((resolve, reject) => {
    printer.PrintLabel(tmpl, data).then(function (res) {
      resolve(res)
    }).catch(function (reason) {
      reject(reason)
    })
  })
}

/**
 * 打印标签列表
 * @param {String} tmpl
 * @param {Array} list
 */
export const printRFIDTags = (tmpl: string, list: any[]) => {
  if (!isHcBrowser()) {
    return
  }
  let printer = getPluginObject('HC.Plugin.Print.LabelPrinter')
  return new Promise((resolve, reject) => {
    printer.PrintLabelList(tmpl, list).then(function (res) {
      resolve(res)
    }).catch(function (reason) {
      reject(reason)
    })
  })
}
